<% add_decidim_page_title(t(".title")) %>
<div class="card" id="registration_types">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t(".title") %>
      <% if allowed_to? :create, :registration_type %>
         <%= link_to t("actions.new_registration_type", scope: "decidim.admin"), new_conference_registration_type_path(current_conference), class: "button button__sm button__secondary new" %>
      <% end %>
    </h1>
  </div>
  <div class="table-stacked">
    <table class="table-list">
      <thead>
        <tr>
          <th><%= t("models.registration_type.fields.title", scope: "decidim.admin") %></th>
          <th><%= t("models.registration_type.fields.price", scope: "decidim.admin") %></th>
          <th><%= t("models.registration_type.fields.weight", scope: "decidim.admin") %></th>
          <th><%= t("models.registration_type.fields.conference_meetings", scope: "decidim.admin") %></th>
          <th><%= t("models.registration_type.fields.registrations_count", scope: "decidim.admin") %></th>
          <th><%= t("models.registration_type.fields.actions", scope: "decidim.admin") %></th>
        </tr>
      </thead>
      <tbody>
        <% @registration_types.each do |registration_type| %>
          <tr>
            <td data-label="<%= t("models.registration_type.fields.title", scope: "decidim.admin") %>">
              <%= translated_attribute(registration_type.title) %>
            </td>
            <td data-label="<%= t("models.registration_type.fields.price", scope: "decidim.admin") %>">
              <%= registration_type.price %>
            </td>
            <td data-label="<%= t("models.registration_type.fields.weight", scope: "decidim.admin") %>">
              <%= registration_type.weight %>
            </td>
            <td data-label="<%= t("models.registration_type.fields.conference_meetings", scope: "decidim.admin") %>">
              <%= registration_type.conference_meeting_registration_types.count %>
            </td>
            <td data-label="<%= t("models.registration_type.fields.registrations_count", scope: "decidim.admin") %>">
              <%= registration_type.conference_registrations.count %>
            </td>

            <td class="table-list__actions" data-label="<%= t("models.registration_type.fields.actions", scope: "decidim.admin") %>">
              <button type="button" data-controller="dropdown" data-target="actions-conference-registration-type-<%= registration_type.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: translated_attribute(registration_type.title)) %>">
                <%= icon "more-fill", class: "text-secondary" %>
              </button>

              <div class="inline-block relative">
                <ul id="actions-conference-registration-type-<%= registration_type.id %>" class="dropdown dropdown__action" aria-hidden="true">
                  <% if allowed_to?(:update, :registration_type, registration_type: registration_type) && !registration_type.conference_registrations.any? %>
                    <li class="dropdown__item">
                      <%= link_to edit_conference_registration_type_path(current_conference, registration_type), class: "dropdown__button" do %>
                        <%= icon "pencil-line" %>
                        <%= t("actions.edit", scope: "decidim.admin") %>
                      <% end %>
                    </li>

                    <hr>
                  <% end %>

                  <% if allowed_to?(:update, :registration_type, registration_type: registration_type) %>
                    <% if registration_type.published? %>
                      <li class="dropdown__item">
                        <%= link_to conference_registration_type_publish_path(current_conference, registration_type), method: :delete, class: "dropdown__button" do %>
                          <%= icon "close-circle-line" %>
                          <%= t("actions.unpublish", scope: "decidim.admin") %>
                        <% end %>
                      </li>
                    <% else %>
                      <li class="dropdown__item">
                        <%= link_to conference_registration_type_publish_path(current_conference, registration_type), method: :post, class: "dropdown__button" do %>
                          <%= icon "check-line" %>
                          <%= t("actions.publish", scope: "decidim.admin") %>
                        <% end %>
                      </li>
                    <% end %>

                    <hr>
                  <% end %>

                  <% if allowed_to?(:destroy, :registration_type, registration_type: registration_type) && !registration_type.conference_registrations.any? %>
                    <li class="dropdown__item">
                      <%= link_to conference_registration_type_path(current_conference, registration_type), method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button" do %>
                        <%= icon "delete-bin-line" %>
                        <%= t("actions.destroy", scope: "decidim.admin") %>
                      <% end %>
                    </li>
                  <% end %>
                </ul>
              </div>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
</div>

<%= decidim_paginate @registration_types %>
